<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        //当左侧的变量数量少于右侧的元素个数时，则忽略多余的元素
        var arr = [1,2,3];
        [a,b] = arr;
        console.log(a,b);

        //当左侧的变量数量多于右侧的元素个数时，则多余的变量会被初始化为undefined
        var arr = [1,2,3];
        [a,b,c,d] = arr;
        console.log(a,b,c,d);

        //两个变量数值的交换
        var num1 = 2;
        var num2 = 3;
        [num1,num2] = [num2,num1];
        console.log(num1,num2);
    </script>
</head>
<body>
    
</body>
</html>